;
var _pageUrl = "/htmlWeb/keyword/list";
var pageGrid;
function detailData(index) {
    gotoHtml(index, 2);
}
function editData(index) {
    gotoHtml(index, 1);
}
function gotoHtml(index, type) {
    $.ajaxSetup({cache: false});
    $(".mainDiv").load('htmlWeb/systemKeywordNewHtml', '', function () {
        $("#id").val(index);
        $("#opType").val(type);
        $.getScript("../../by-webhtml/assets/js/system/system_keywordNew.js");
    });
}
function init() {
    $.post("htmlWeb/keyword/getOption", function (data) {
        var _noOpt = "", _keyParent = "";
        $.each(data.status, function (index, obj) {
            var opt = obj.split(";");
            _noOpt += '<option value="' + opt[0] + '">' + opt[1] + '</option>'
        });
        $.each(data.parentId, function (index, obj) {
            _keyParent += '<option value="' + obj.id + '">' + obj.name + '</option>'
        });
        $("#parentId").append(_keyParent);
        $("#status").append(_noOpt);
    });
    $("#add").click(function () {
        gotoHtml(null, 0);
    });
    $(".conBut").click(function () {
        var s = $("#searchForm").serializeSearchForm();
        pageGrid.search(s);
    });
}
function delData(id) {
    $.ajax({
        url:"htmlWeb/keyword/delKeyword",
        type:'POST',
        dataType:"json",
        data:{
            id:id
        },
        success:function(result){
            if(result.msg == 'success'){
                alert("删除关键字成功");
                $(".conBut").click();
            }else {
                alert("删除关键字失败");
            }
        }
    });
}
function pageBar() {
    pageGrid=  $("#pager").createPage({
        url: _pageUrl,
        ajaxBackFn: function (data) {
            var _gridHtml = '';
            $.each(data.rows, function (index, row) {
                _gridHtml += '<tr>' +
                    '<td><input type="hidden" class="rowid" value=\"' + row.id + '\"><p>' + row.id + '</p></td>' +
                    '<td><p>' + row.positionName + '</p></td>' +
                    '<td><p>' + row.name + '</p></td>' +
                    '<td><p>' + (row.sort == null ? '':row.sort) + '</p></td>' +
                    '<td><p>' + (row.descn == null ? '':row.descn) + '</p></td>' +
                    '<td><p>' + row.statusName + '</p></td>' +
                    '<td><span class="userSpan"><p>' +
                    '<a href="javascript:editData(' + row.id + ')">编辑</a>' +
                    '<a href="javascript:delData(' + row.id + ')">删除</a>' +
                    // '<a class="ico" href="javascript:detailData(' + row.id + ')">详情</a>' +
                    '</p></span></td></tr>';
            });
            $("#keywordGrid tr:not(:first)").html("");
            $('#keywordGrid').append(_gridHtml);
        }
    });
}
$(function () {
    init();
    pageBar();
});
